home *** CD-ROM | disk | FTP | other *** search
Text File | 2001-02-20 | 9.9 KB | 482 lines | [AMAS/AMAP] |
- // -* TSObject.js *-
- //
- // Description: Functions for accessing and building 3Space objects
- // Author:
- // Version: $Id: TSObject.js,v 1.7 2000/10/10 09:22:08 consumer Exp $
- //
-
- //
- // Node
- //
-
- function nodeGetFromID(id)
- {
- var node = gXMLObject.nodeFromID(id);
- if (node == null) {
- error("Node '" + id + "' not found!");
- }
-
- return node;
- }
-
- function nodeGetID(node)
- {
- return nodeObjectFindAttribute(node, 'id');
- }
-
- function makeNode(name, id)
- {
- //var node = gXMLObject.createNode(1, name, "x-schema:3Space/Schemas.xml");
- //node.setAttribute('id', id);
-
- //return node;
-
- }
-
- /*function nodeUpdate(id)
- {
- gPlayer.UpdateXMLNode(id);
- }
- */
- function updateNode (nodeId) {
- gPlayer.UpdateXMLNode (nodeId) ;
- }
-
- function updateNodeAttribute (nodeId, attributeName, attributeValue) {
- gPlayer.UpdateXMLNodeAttr (nodeId, attributeName, attributeValue) ;
- }
-
- function nodeGetAttribute(id, attribute)
- {
- var attr = gPlayer.GetAttribute(id, attribute);
- if (attr == "") {
- error("Attribute '" + id + "' not found!");
- }
-
- return attr;
- }
-
- /*
- function nodeUpdateAttribute(id, attribute, value)
- {
- //alert("Update attribute: { '" + id + "'; '" + attribute + "'; '" + value + "' }");
- gPlayer.UpdateXMLNodeAttr(id, attribute, value);
- }
- */
-
- /*function nodeAppendChild(id, child)
- {
- nodeGetFromID(id).appendChild(child);
- gPlayer.updateXMLNode(nodeGetID(child));
- }*/
-
- function appendChild (parentId, nodeId) {
- gPlayer.appendChild (parentId, nodeId) ;
- }
-
- /*function nodeRemove(id)
- {
- gPlayer.removeXMLNode(id);
- }
- */
- function removeNode (nodeId) {
- gPlayer.removeXMLNode (nodeId) ;
- }
-
- function nodeObjectFindAttribute(node, attributeName)
- {
- var attributes = node.attributes;
-
- if (attributes.length != 0) {
- for (i = 0; i < attributes.length; i++) {
- var attrNode = attributes.item(i);
- if (attrNode.nodeName == attributeName)
- return attrNode.value;
- }
- }
- return null;
- }
-
- function nodeFindAttribute(id, attributeName)
- {
- return nodeObjectFindAttribute(nodeGetFromID(id), attribute);
- }
-
- function nodeFindFirstChild(id, childName)
- {
- var nodeList = nodeGetFromID(id).childNodes;
-
- if (nodeList.length == 0)
- return null;
-
- for (i = 0; i < nodeList.length; i++) {
- var childNode = nodeList.item(i);
- if (childNode.nodeName == childName)
- return nodeGetID(childNode);
- }
- }
-
- //
- // Basic solid
- //
-
- function makeSolid(id, fixed, position)
- {
- var solid = makeNode("Solid", id);
-
- solid.setAttribute('fixed', fixed);
- solid.setAttribute('position', position);
-
- return solid;
- }
-
- function solidGetPosition(solidName)
- {
- return makePointFromString(nodeGetAttribute(solidName, 'position'));
- }
-
- function solidGetBoundingBox(solidName)
- {
- return makeBoundingBoxFromString(nodeGetAttribute(solidName, 'boundingBox'));
- }
-
- function solidGetLengthX(solidName)
- {
- return boundingBoxGetLengthX(solidGetBoundingBox(solidName));
- }
-
- function solidGetLengthY(solidName)
- {
- return boundingBoxGetLengthY(solidGetBoundingBox(solidName));
- }
-
- function solidGetLengthZ(solidName)
- {
- return boundingBoxGetLengthZ(solidGetBoundingBox(solidName));
- }
-
- //
- // Basic geometry
- //
-
- function makeBlock(id, color, lengthX, lengthY, lengthZ)
- {
- var block = makeNode("GeomBlock", id);
-
- block.setAttribute('color', color);
- block.setAttribute('lengthX', lengthX);
- block.setAttribute('lengthY', lengthY);
- block.setAttribute('lengthZ', lengthZ);
-
- return block;
- }
-
- function makeCone(id, length, radius, color)
- {
- var cone = makeNode("GeomCone", id);
-
- cone.setAttribute('color', color);
- cone.setAttribute('length', length);
- cone.setAttribute('radius', radius);
-
- return cone;
- }
-
- function makeCube(id, length, color)
- {
- var cube = makeNode("GeomCube", id);
-
- cube.setAttribute('color', color);
- cube.setAttribute('length', length);
-
- return cube;
- }
-
- function makeCylinder(id, length, radius, color)
- {
- var cylinder = makeNode("GeomCylinder", id);
-
- cylinder.setAttribute('color', color);
- cylinder.setAttribute('length', length);
- cylinder.setAttribute('radius', radius);
-
- return cylinder;
- }
-
- function makePlan(id, length, width, color)
- {
- var plan = makeNode("GeomPlan", id);
-
- plan.setAttribute('color', color);
- plan.setAttribute('length', length);
- plan.setAttribute('width', width);
-
- return plan;
- }
-
- function makeSphere(id, radius, color)
- {
- var sphere = makeNode("GeomSphere", id);
-
- sphere.setAttribute('color', color);
- sphere.setAttribute('radius', radius);
-
- return sphere;
- }
-
- function makeText(id, text, size, color)
- {
- var text = makeNode("GeomText", id);
-
- text.setAttribute('color', color);
- text.setAttribute('text', text);
- text.setAttribute('text', size);
-
- return text;
- }
-
- //
- // Light
- //
-
- function makeSolidPointLight(id, position, color, state)
- {
- var light = makeNode("SolidPointLight", id);
-
- light.setAttribute('fixed', '1');
- light.setAttribute('position', position);
- light.setAttribute('color', color);
- light.setAttribute('state', state);
-
- return light;
- }
-
- function makeSolidSpotLight(id, position, direction, cutOffAngle, dropOffAngle, color, state)
- {
- var light = makeNode("SolidSpotLight", id);
-
- light.setAttribute('fixed', '1');
- light.setAttribute('position', position);
- light.setAttribute('direction', direction);
- light.setAttribute('cutOffAngle', cutOffAngle);
- light.setAttribute('dropOffAngle', dropOffAngle);
- light.setAttribute('color', color);
- light.setAttribute('state', state);
-
- return light;
- }
-
- //
- // Camera
- //
-
- function cameraGetPosition(id)
- {
- return solidGetPosition(id);
- }
-
- function cameraGetTargetPosition(id)
- {
- return makePointFromString(nodeGetAttribute(id, 'targetPoint'));
- }
-
- function cameraLookAt(id, targetPoint)
- {
- nodeUpdateAttribute(id, 'targetPoint', targetPoint)
- }
-
- function cameraLookAtSolid(id, targetID)
- {
- nodeUpdateAttribute(id, 'target', targetID);
- }
-
- //
- // Particle systems
- //
-
- function makeParticleSystem(id,
- textureFile,
- position,
- rotation,
- yawVariation,
- pitchVariation,
- initialColor,
- endColor,
- initialSize,
- endSize,
- speed,
- speedVariation,
- lifeSpan,
- lifeSpanVariation)
- {
- var psystem = makeNode("ParticleSystem");
-
- psystem.setAttribute('id', id);
- psystem.setAttribute('particleTexture', textureFile);
- psystem.setAttribute('position', position);
- psystem.setAttribute('rotation', rotation);
- psystem.setAttribute('yawVariation', yawVariation);
- psystem.setAttribute('pitchVariation', pitchVariation);
- psystem.setAttribute('initialColor', initialColor);
- psystem.setAttribute('endColor', endColor);
- psystem.setAttribute('initialSize', initialSize);
- psystem.setAttribute('endSize', endSize);
- psystem.setAttribute('speed', speed);
- psystem.setAttribute('speedVariation', speedVariation);
- psystem.setAttribute('lifeSpan', lifeSpan);
- psystem.setAttribute('lifeSpanVariation', lifeSpanVariation);
-
- return psystem;
- }
- /*
- function makeBurnParticleSystem(id,
- textureFile,
- position,
- rotation,
- intensity,
- size)
- {
- var yawVar = '5';
- var pitchVar = '5';
- var initialColor = '1 0.5 0';
- var endColor = '1 1 1';
- var initialSize = new String(size);
- var endSize = new String(0.05 * size);
- var speed = new String(0.00005 * size * intensity);
- var speedVariation = new String(0.000005 * size * intensity);
- var lifeSpan = new String(100000 * size * intensity / 100);
- var lifeSpanVariation = new String(1000 * size * intensity / 100);
-
- return makeParticleSystem(id,
- textureFile,
- position,
- rotation,
- yawVar,
- pitchVar,
- initialColor,
- endColor,
- initialSize,
- endSize,
- speed,
- speedVariation,
- lifeSpan,
- lifeSpanVariation);
- }
- */
- function makeBurnParticleSystem(id,
- textureFile,
- position,
- rotation,
- intensity,
- size)
- {
- var yawVar = '5';
- var pitchVar = '5';
- var initialColor = '1 0.5 0';
- var endColor = '1 1 1';
- var initialSize = new String(0.9 * size);
- var endSize = new String(0.3 * size);;
- var speed = '0.01';
- var speedVariation = '0.005';
- var lifeSpan = '800';
- var lifeSpanVariation = '200';
-
- return makeParticleSystem(id,
- textureFile,
- position,
- rotation,
- yawVar,
- pitchVar,
- initialColor,
- endColor,
- initialSize,
- endSize,
- speed,
- speedVariation,
- lifeSpan,
- lifeSpanVariation);
- }
-
- //
- // Forces
- //
-
- function makeDampingSolidForce(id, angular, linear)
- {
- var damping = makeNode("DampingSolidForce", id);
-
- damping.setAttribute('angular', angular);
- damping.setAttribute('linear', linear);
-
- return damping;
- }
-
- function makeSpringForce(id, constant, damping, point, target)
- {
- var spring = makeNode("SpringForce", id);
-
- spring.setAttribute('constant', constant);
- spring.setAttribute('damping', damping);
- spring.setAttribute('point', point);
- spring.setAttribute('target', target);
-
- return spring;
- }
-
- function makeDragForce(id, intensity, dragPoint, targetPoint)
- {
- var drag = makeNode("DragForce", id);
-
- drag.setAttribute('intensity', intensity);
- drag.setAttribute('dragPoint', dragPoint);
- drag.setAttribute('targetPoint', targetPoint);
-
- return drag;
- }
-
- function makeShootForce(id, direction, intensity, point)
- {
- var shoot = makeNode("ShootForce", id);
-
- shoot.setAttribute('direction', direction);
- shoot.setAttribute('intensity', intensity);
- shoot.setAttribute('point', point);
-
- return shoot;
- }
-
- //
- // Links
- //
-
- function makeAxisLink(id, axis, point, target)
- {
- var link = makeNode("AxisLink", id);
-
- link.setAttribute('axis', axis);
- link.setAttribute('point', point);
- link.setAttribute('target', target);
-
- return link;
- }
- function makeCylindricalLink(id, axis, point, target)
- {
- var link = makeNode("CylindricalLink", id);
-
- link.setAttribute('axis', axis);
- link.setAttribute('point', point);
- link.setAttribute('target', target);
-
- return link;
- }
-
- function makeSphericalLink(id, point, target)
- {
- var link = makeNode("SphericalLink", id);
-
- link.setAttribute('point', point);
- link.setAttribute('target', target);
-
- return link;
- }
-